/*
The surface-physics project: http://code.google.com/p/surface-physics/
Adds real world physics based on the Bullet physics engine, to bases in the Orbiter space
flight simulation software.

Written by Abhijit Nandy
License : Apache License 2.0


This file declares a common class for a pointer
that can  point at different type of objects(sub classed in AttachmentLibrary and ComponentLibrary).

AttachmentLibrary : contains primarily objects which are VESSELs controlled via attachment points
ComponentLibrary  : contains objects that do not require attachment points but may use it if necess.

Bump_Task also contains the world transform m[16] that is a common member to both objects types
and thus can be factored out, into this class.

		   Bump_Task (parent)
            /		  \
           /           \
	Bump_ATV		Bump_ExternalStaticGeometry (derived)


*/


#pragma once

#include "../Engine/PhysicsEngine.h"
#include "../BulletBase/Bump_BulletBase.h"
//#include <btBulletDynamicsCommon.h>


extern PhysicsEngine bump;

extern char boutput[1000];

#define MAX_STRLEN 50

/**
 * The Bump_Task to derive classes meant to control objects attached/part of a BulletBase
 * Objects of this class appear *inside* objects of Bump_BulletBase
 */
class Bump_Task
{



protected:
	//Physics stuff : Primary rigid body, collision shape ptr etc.
	btRigidBody *rb;


	//World transform of primary rigid body
	//common to all physics objects(whether they have more transforms or not)
	btScalar m[16];



	bool physicsInited;

	//The containing Bump_BulletBase
	Bump_BulletBase *bumpBase;


public:

	char strObjectName[MAX_STRLEN];

	/**
	 * Delete when inactive, flag, prevents removal by containing section if set
	 * This also prevents the current owning section of this object from being deleted
	 *
	 * This is required to prevent certain dynamic objects from being removed: such as
	 * a raycast vehicle based object. If this is not present then dynamic objects will be
	 * deleted when their owning section is deleted and reloaded at their initial position.
	 *
	 * But they may not have been in their initial position when deleted(being dynamic), thus user
	 * will see object in different position when he returns.
	 *
	 * By default its false to prevent objects from being deleted. Static derived classes should set it
	 * to true as well other objects which do not need to persist their position between loads.
	 */
	bool deleteIfInactive;


	/**
	 * Update delay is the number of sim steps for which prestep() or poststep() need not
	 * be called after it has been called in the current step. This can be INFINITY which means that
	 * prestep() & poststep() will never be called for that object
	 * Objects should set the update delay when inactive or when it need not receive updates for a
	 * few cycles. This prevents unnecessary function calls from the base, requesting updates.
	 *
	 * The count variables are used by the base to countdown to next call of these 2 functions separately.
	 */
	int updatePreStepDelay;
	int updatePostStepDelay;
	int updatePreStepDelayRemCount;
	int updatePostStepDelayRemCount;

	//Part of templated object creation, WIP
	static const int index = 1;

	//Constructor, destructor

	Bump_Task(){};
	Bump_Task(Bump_BulletBase *bb, char *strObjName);
	virtual ~Bump_Task();


	//TODO: decide whether to provide a parent class impl. or make these purely virtual
	virtual int		init();
	virtual int		prestep(double SimT, double SimDT, double MJD);
	virtual int		poststep(double SimT, double SimDT, double MJD);
	virtual	int		reset();
	virtual int 	exit();

};
